package com.gym.code.generator.impl.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.gym.code.generator.Contants;
import com.gym.code.generator.impl.AbstractFaceGenerator;
import com.gym.code.generator.model.mapping.layer.service.IServiceLayerGenerateModel;
import com.gym.code.generator.model.mapping.method.AbstractMethodGenerateModel;
import com.gym.code.generator.model.mapping.method.MethodDeleteModel;
import com.gym.code.generator.model.mapping.method.MethodInsertModel;
import com.gym.code.generator.model.mapping.method.MethodSelectModel;
import com.gym.code.generator.model.mapping.method.MethodUpdateModel;

/**
 * 
 * @author xinchun.wang
 * @email: 532002108@qq.com
 * @createTime 2015-4-12 上午11:30:51
 */
public class ServiceFaceGenerator extends
		AbstractFaceGenerator<IServiceLayerGenerateModel> {

	private static ServiceFaceGenerator instance = new ServiceFaceGenerator();
	 
	public static ServiceFaceGenerator getInstance(){
		return instance;
	}
	
	@Override
	protected List<String> generateClassBegin(IServiceLayerGenerateModel bean) {
		List<String> result = new ArrayList<String>();
		result.add("public interface " + getIServiceName(bean) + " {");
		return result;
	}

	@Override
	protected List<String> generateFields(IServiceLayerGenerateModel bean) {
		return Collections.emptyList();
	}

	@Override
	protected List<String> generateMethods(IServiceLayerGenerateModel bean) {
		List<String> result = new ArrayList<String>();
		for (AbstractMethodGenerateModel method : bean.getMethodModelList()) {
			if (method instanceof MethodDeleteModel) {
				result.add(generateMethodDeclare(method) + ";");
			} else if (method instanceof MethodUpdateModel) {
				result.add(generateMethodDeclare(method) + ";");
			} else if (method instanceof MethodSelectModel) {
				result.add(generateSelectMethodDeclare((MethodSelectModel) method)
						+ ";");
			} else if (method instanceof MethodInsertModel) {
				result.add(generateMethodDeclare(method) + ";");
			}
		}
		return result;
	}

	@Override
	protected String generatePackage(IServiceLayerGenerateModel bean) {
		return "package " + bean.getPackageName() + Contants.$lineSplit;
	}
}
